package com.scalar.chiptrack.rma;

import java.util.Calendar;

import com.scalar.chiptrack.commons.Address;
import com.scalar.chiptrack.rma.dao.RmaDAO;
import com.scalar.chiptrack.rma.forms.RMAForm;
import com.scalar.chiptrack.sales.Customer;
import com.scalar.chiptrack.utils.StringUtils;

public class RMAUtil
{
    public static void setCustomerDetailsFromChipTrac( RMAForm form, Customer customer )
    {
		//RMA number generation is client specific we need to take action when we are implementing Full blown system.

		Calendar calendar = Calendar.getInstance();
		java.util.Date date = calendar.getTime();

        form.setRmaNumber(RmaDAO.getAutoRMANumber());
		form.setRmaRequestDate(StringUtils.formatDateToString ( date , "MM/dd/yyyy" ));
		form.setRmaIssueDate(StringUtils.formatDateToString ( date , "MM/dd/yyyy" ));

		form.setCustomerId(customer.getCustomerId());
		form.setCustomerName(customer.getCustomerName());
		form.setContactPerson(customer.getContactPerson());

		Address billingAddress = customer.getBillingAddress();
		form.setEmail(billingAddress.getEmail());
		form.setPhoneNumber(billingAddress.getPhoneNumber());
		form.setFaxNumber(billingAddress.getFaxNumber());

		String billAddress = billingAddress.getAddress1()+"\n"+billingAddress.getAddress2();
        billAddress += billingAddress.getCity()+" "+billingAddress.getState()+" " +billingAddress.getZipCode();

		form.setBillingAddress(billAddress);
		form.setAddress1(billingAddress.getAddress1());
		form.setAddress2(billingAddress.getAddress2());
        form.setAddress3(billingAddress.getAddress3());
        form.setAddress4(billingAddress.getAddress4());
		form.setCity(billingAddress.getCity());
		form.setState(billingAddress.getState());
		form.setZipcode(billingAddress.getZipCode());
        form.setCountry(billingAddress.getCountry());
		form.setBillingAddressId(customer.getDefaultBillingAddressId());

	}

}